import React from 'react'
import { inject, observer } from 'mobx-react';
import { toJS } from "mobx"
import isEqual from 'lodash'
import { Form, RouteLayout } from 'weaver-mobile-page';
import { Tools } from 'weaver-mobile'
import { withRouter } from 'react-router-dom'

const ButtonGroup = RouteLayout.ButtonGroup;
const getLabel = Tools.getLabel;

@withRouter
@observer
export default class AdvancedItem extends React.Component {
    componentWillMount() {
    }

    getFields = () => {
        const { advancedItem } = this.props.store;
        const { form } = advancedItem;
        const { conditioninfo, isInit } = form;
        const fields = [];
        if (isInit) {
            conditioninfo.forEach((group) => {
                group.items.forEach((field) => {
                    fields.push(<Form.Item
                        key={field.domkey.join('__')}
                        form={form}
                        fieldConfig={field}
                        onChange={form.onChange}
                    />);
                });
            });
        }
        return fields;
    }

    onChange = (condition, value) => {
        const { advancedItem } = this.props.store;
        const { form } = advancedItem;
        form.onChange(condition, value);


    }    

    render() {
        const { advancedItem, getTicketHolderList,selectKeyTop,mark,setNameQuery,setStateParams,options } = this.props.store;
        const { form } = advancedItem;

        return (// 
            <div className="advancedItem" style={{height:"100%"}}>
                <div style={{ height: "calc(100% - 47px)", overflowY:"auto" }}>
                    <Form store={form} onChange={this.onChange} />
                </div>
                <div className='wf-agent-advancedItem-button-group'>
                    <ButtonGroup
                        data={[
                            {
                                key: 'reset',
                                text: getLabel(2022,"重置"),
                                className: "wf-agent-advancedItem-button-reset",
                                onClick: () => {
                                    // const { form } = this.props.store.advancedItem;
                                    form.resetFields();
                                },
                            },
                            {
                                key: 'save',
                                text: getLabel(826,"确定"),
                                onClick: () => {
                                    setStateParams({onRowSelect:[],allMoney:0});
                                    for(let i=0,len = options.length;i<len;i++){
                                        if(options[i].key == form.formParams.advQry_invoiceType){
                                            setNameQuery(options[i].showname);
                                            break;
                                        }
                                    }

                                    let orderKey = '';
                                    for(let k in mark){
                                        if(mark[k] === 0 || mark[k] === 1){
                                            orderKey = k;
                                        }
                                    }
                                    
                                    let params = {
                                        ...form.formParams,
                                        status:selectKeyTop,
                                        orderKey:orderKey,
                                        order:mark[orderKey],
                                    };

                                    getTicketHolderList(params);
                                    this.props.history.go(-1);
                                },
                                type: "primary"
                            }
                        ]}
                    />

                </div>
            </div>
        )
    }

}